//////////////////////////////////////page pagination control utill/////////////////////////////////////////
/**
designed by chenjb.
use as :
	//table4 is the id of the table that you want to control the pagination.
	var table4ctrbtn2 =new PaginatedCtrl('table4','table4ctrbtn2');
	//splidpagebnt this the target where you want to place the control button.
	table4ctrbtn2.builder('splidpagebnt');
	// set the number rows of one page to show
	table4ctrbtn2.setShowCount(6);
	// go to the first page .
	table4ctrbtn2.toPage(1);000
*/
var str='';
str+='<style>';
str+='<!--'
str+='.gotoinput {'
str+='	height: 16;'
str+='	font-size: 12px;'
str+='	text-decoration: none;'
str+='	outline-style: dotted;'
str+='	border-color: #000000; border-width: 1px;'
str+='}'

str+='.listtitle_black {font-size: 12px;	line-height: 24px;	text-decoration: none;	color: #333333;	font-weight: bold;}'

str+='.page_normal {	font-size: 12px;	line-height: 24px;	color: #333333;	text-decoration: none;}'

str+='.t_rightunderline {	border-right-width: 1px;	border-right-style: solid;	border-right-color: #999999;	border-bottom-width: 1px;	border-bottom-style: solid;	border-bottom-color: #999999;}'

str+='.t_underline {	border-bottom-width: 1px;	border-bottom-style: solid;	border-bottom-color: #999999;}'

str+='.check_box {orphans: inherit;text-decoration: none;border-left:none; border-right:none; border-top:none;border-bottom: none;}'
str+='.scrollpagestyle2 {	font-size: 12px;	line-height: 24px;	color: #cc6600;	text-decoration: none;}'
str+='.a.navi_2nd:link {	font-size: 12px;	line-height: 24px;	color: #0033cc;	text-decoration: none;	cursor: hand}'

str+='.navi_2nd {	font-size: 12px;	line-height: 24px;	color: #0033cc;	text-decoration: none;;	cursor: hand}'
str+='.comword {	font-size: 12px;	line-height: 24px;	text-decoration: none;;	cursor: hand}'
str+='.inputSearch {	height: 15; font-size: 10px;	text-decoration: none;	outline-style: dotted;	border-color: #000000;	border-width: 1px;	background-color: #f4f4f4}'
str+='.trh{display: none; font-size: 14px; font-family:宋体; text-align:center; }'
str+='.trs{display: block; font-size: 14px; font-family:宋体; text-align:center; }'
str+='.table-header {font-size: 13px; height: 22;}'
str+='.table-content {font-size: 13px;}'
str+='.table-footer {font-size: 13px;}'
str+='.a-content {text-decoration: none; cursor: hand; color: #0000FF}'
str+='.A:hover { color:red; text-transform:uppercase; letter-spacing:1cm }'
str+='.A:active { font-weight:bold; color:purple }'
str+='.A:visited { color:blue }'
str+='.A:link { color:#FF0000 }'
str+='-->'
str+='</style>'

document.write(str);
// paginate the table

function PaginatedCtrl(tbl,name){//PaginatedCtrl 
	this.crollPage=true;
	this.name=name;
	this.tbl=document.getElementById(tbl);
	this.pageCount=0;
	this.defaultShowCount=10;
	this.rowsCount=this.tbl.rows.length;
	this.showCount=10;
	this.currentPage=1;
	this.prevPageNo=1;
	this.startIndex=0;
	this.endIndex=this.showCount;
	this.pageCode=null;
	this.pageCount=null;
	this.rowsNumber=null;
	//alert(this.name);
}

//������ʾ������
PaginatedCtrl.prototype.setShowCount= function(showCount){ 
	if(showCount){
		this.showCount=showCount;
	}
	this.reinitPars();
}

PaginatedCtrl.prototype.reinitPars=function(){
	var temp=parseInt(this.rowsCount / this.showCount);
		if((this.rowsCount  % this.showCount)!=0){
		 	this.pageCount=parseInt(temp)+1;
		 }else{
		    this.pageCount=parseInt(temp);
		 }
}

PaginatedCtrl.prototype.builder= function(target){ 
	var strHtml='';
	this.crollPage=true;
	if(this.crollPage){
		strHtml += '<table border="0" cellpadding="2" cellspacing="0" class="comword"> <tr><td align="right" >';
		strHtml += '<span class="scrollpagestyle1">';
		strHtml += '<span id="firstPage" title="First Page">[<a class="navi_2nd" href="javascript:' + this.name + '.toPage(1);">首页</a></span>&nbsp;';
		strHtml += '<span id="prevPage" title="Prev Page"><a class="navi_2nd" href="javascript:' + this.name + '.toPrevPage();">上一页</a>&nbsp;</span>&nbsp;';
		strHtml += '<span id="nextPage" title="Next Page"><a class="navi_2nd" href="javascript:' + this.name + '.toNextPage();">下一页</a>&nbsp;</span>&nbsp;';
		strHtml += '<span id="lastPage" title="Last Page"><a class="navi_2nd" href="javascript:' + this.name + '.toPage(' + this.pageCount + ');">末页</a></span>]';
		strHtml += '&nbsp;&nbsp;&nbsp;<span class="scrollpagestyle1"><span id="' + this.name + 'pageCode">1</span>/<span id="' + this.name + 'pageCount">1</span></span>';
		strHtml += '&nbsp;&nbsp;<span id="' + this.name + 'rowsNumber">0</span>&nbsp;条';
		strHtml += '</span></td>';
		strHtml += '<td class="scrollpage" align="center" nowrap>';
		strHtml += '&nbsp;&nbsp;&nbsp;到:&nbsp; <input type="text" class="gotoinput" name="consumerPageNum" id="consumerPageNum" size="2" maxlength="4" onkeypress="javascript:'+this.name+'.consumerPage();">页';
		strHtml += '&nbsp;<input type="button" class="inputSearch" style="cursor:hand;height:18;" value="GO" onclick="'+this.name+'.buttonActionConsumerPage();"></td>';
		strHtml += '</tr></table>';
	}else{
		strHtml += '<table style="display:none;" width="100%" border="0" cellpadding="2" cellspacing="0" class="page_normal"> <tr><td width="86%" align="right" >';
		strHtml += '<span class="scrollpagestyle1">';
		strHtml += '<span id="firstPage" title="First Page">[<a class="scrollpagestyle2" href="javascript:' + this.name + '.toPage(1);">首页</a></span>&nbsp;';
		strHtml += '<span id="prevPage" title="Prev Page"><a class="scrollpagestyle2" href="javascript:' + this.name + '.toPrevPage();">上一页</a>&nbsp;</span>&nbsp;';
		strHtml += '<span id="nextPage" title="Next Page"><a class="scrollpagestyle2" href="javascript:' + this.name + '.toNextPage();">下一页</a>&nbsp;</span>&nbsp;';
		strHtml += '<span id="lastPage" title="Last Page"><a class="scrollpagestyle2" href="javascript:' + this.name + '.toPage(' + this.pageCount + ');">末页</a></span>]';
		strHtml += '&nbsp;&nbsp;&nbsp;<span class="scrollpagestyle1">\u7b2c<span id="pageCode">1</span>\u9875 </span>';
		strHtml += '&nbsp;&nbsp;&nbsp;\u5171<span id="rowsNumber">0</span>\u6761\u8bb0\u5f55';
		strHtml += '</span></td>';
		strHtml += '<td class="scrollpage" align="center" nowrap>';
		strHtml += '\u8f6c\u5230:&nbsp; <input type="text" class="gotoinput" name="consumerPageNum" id="consumerPageNum" size="2" maxlength="4" onkeypress="javascript:'+this.name+'.consumerPage();"> \u9875';
		strHtml += '</td>';
		strHtml += '</tr></table>';
	
	}
	
	document.getElementById(target).innerHTML=strHtml;
	
}

//��ʾ��ǰ��ʾ��ҳ�롣
PaginatedCtrl.prototype.showCurrentPage= function(){
	var pageCodes= document.getElementById(this.name+"pageCode");//' + this.name + '
	var pageCountObj=document.getElementById(this.name+'pageCount');
	if(null!=pageCodes && ""!=pageCodes)
	{
	     if(this.currentPage>0 && this.currentPage<=this.pageCount)
	     {
	     	pageCodes.innerHTML=this.currentPage;
	     	pageCountObj.innerHTML=this.pageCount;
	     }
	}
}

//scroll page button control
PaginatedCtrl.prototype.buttonControl = function(page){ 
	var firstButton=document.getElementById("firstPage");
	var firstContent='[<a class="navi_2nd" href="javascript:' + this.name + '.toFirstPage();">首页</a>';
	var prevButton=document.getElementById("prevPage");
	var prevContent='<a class="navi_2nd" href="javascript:' + this.name + '.toPrevPage();">|上一页</a>';
	var nextButton=document.getElementById("nextPage");
	var nextContent='<a class="navi_2nd" href="javascript:' + this.name + '.toNextPage();">|下一页|</a>';
	var lastButton=document.getElementById("lastPage");
	var lastContent='<a class="navi_2nd" href="javascript:' + this.name + '.toLastPage();">末页</a>';
	//var firstButtonHref=firstButton.
	if(parseInt(this.pageCount)==1){
		firstButton.innerHTML='[首页';
	  	prevButton.innerHTML='|上一页';
	  	nextButton.innerHTML='|下一页|';
	    lastButton.innerHTML='末页';
	}
	else if(parseInt(page)<=1){
	  this.currentPage=1
	  this.prevPage=1;
	  this.nextPage=parseInt(this.currentPage)+1;
	  //firstpage prevpage invaliable
	  firstButton.innerHTML='[首页';
	  prevButton.innerHTML='|上一页';
	  nextButton.innerHTML=nextContent;
	  lastButton.innerHTML=lastContent;
	}else if(parseInt(page)>=parseInt(this.pageCount)){
	     //alert(page);
	     this.currentPage=this.pageCount;
	     this.prevPage=parseInt(this.currentPage)-1;
	     this.nextPage=parseInt(this.currentPage);
	     //next and last button invalid
	     nextButton.innerHTML='|下一页|';
	     lastButton.innerHTML='末页';
	     firstButton.innerHTML=firstContent;
	     prevButton.innerHTML=prevContent;
	} 
	else{
	  this.prevPage=parseInt(this.currentPage)-1;
	  this.nextPage=parseInt(this.currentPage)+1;
	  // all button is aviable
	  firstButton.innerHTML=firstContent;
	  prevButton.innerHTML=prevContent;
	  nextButton.innerHTML=nextContent;
	  lastButton.innerHTML=lastContent;
	}
	
}

PaginatedCtrl.prototype.showPageCount = function(){ 
	var pageCount= document.getElementById(this.name+"pageCount");
	var rowsNumber=document.getElementById(this.name+"rowsNumber");
	var i;
	if(null!=pageCount && ""!=pageCount){
	     var pageCode;
	     pageCount.innerHTML=this.pageCount;	
	}
	if(rowsNumber){
		rowsNumber.innerHTML=this.rowsCount;
	}
}

PaginatedCtrl.prototype.toFirstPage=function(){
		this.prevPageNo=this.currentPage;
		this.toPage(1);
}

PaginatedCtrl.prototype.toPrevPage=function(){
	if(this.currentPage>1){
		this.prevPageNo=this.currentPage;
		var no=this.currentPage-1;
		this.toPage(no);
	}
}

PaginatedCtrl.prototype.toNextPage=function(){
	//alert('this.currentPage<this.pageCount=='+parseInt(this.currentPage)+'::::::::'+parseInt(this.pageCount));
	
	if(this.currentPage<this.pageCount){
		this.prevPageNo=this.currentPage;
		var no=this.currentPage+1;
		this.toPage(no);
	}
}
PaginatedCtrl.prototype.toLastPage=function(){
		this.prevPageNo=this.currentPage;
		this.toPage(this.pageCount);
}

PaginatedCtrl.prototype.toPage= function(no){
	
	this.currentPage=no;
	this.showCurrentPage();
	
	this.showPageCount();
	
	this.buttonControl(this.currentPage);
	this.calculateShowIndex(no);
	
	var rows=this.tbl.rows;
	var lines=rows.length;
	
	var line;
	this.hideAll();
	//this.hidePrevPage();
	for(var i=this.startIndex;i<this.endIndex;i++){
		line=rows[i];
		line.className="trs";
		if(i%2==0)
		line.style.bgColor="#112233";
		//alert(line.style.bgColor);
	}
}

PaginatedCtrl.prototype.hideAll= function(){
	var rows=this.tbl.rows;
	var lines=rows.length;
	var line;
	for(var i=0;i<lines;i++){
		line=rows[i];
		line.className="trh";
	}
}

//������ʾ�еĿ�ʼ�ͽ����±ꡣ
PaginatedCtrl.prototype.calculateShowIndex = function(page){
	this.startIndex=0;
	this.endIndex=this.showCount;
	var realNum=0;
	this.startIndex=(page-1)*this.showCount;
	if(parseInt(this.pageCount)==parseInt(page)){
		this.endIndex=this.rowsCount;
	}else{
		this.endIndex=this.startIndex+this.showCount;
		if(parseInt(this.endIndex)>parseInt(this.rowsCount)){
			this.endIndex=this.rowsCount;
		}
	}
}

//������һ��ʾҳ������
PaginatedCtrl.prototype.hidePrevPage = function(){
	var page=this.prevPageNo;
	startIndex=(page-1)*this.showCount;
	if(parseInt(this.pageCount)==parseInt(page)){
		endIndex=this.rowsCount;
	}else{
		endIndex=startIndex+this.showCount;
		if(parseInt(endIndex)>parseInt(this.rowsCount)){
			endIndex=this.rowsCount;
		}
	}
	var rows=this.tbl.rows;
	for(var i=startIndex ;i<endIndex;i++){
		rows[i].className='trh';
	}
}

//��ʾ�û����Ƶ�ҳ
PaginatedCtrl.prototype.consumerPage= function(){
	if(event.keyCode==13){
		this.toConsumerPage();
		document.getElementById('consumerPageNum').value='';
	}
	
}

PaginatedCtrl.prototype.buttonActionConsumerPage= function(){
	this.toConsumerPage();
	document.getElementById('consumerPageNum').focus();
}

PaginatedCtrl.prototype.toConsumerPage= function(){
	var inputobj=document.getElementById('consumerPageNum');
	var pageNo=inputobj.value;
	if(pageNo)
		
	if(parseInt(pageNo)>0 && parseInt(pageNo)<=this.pageCount){
		this.prevPageNo=this.currentPage;
		this.toPage(parseInt(pageNo));
	}
}

PaginatedCtrl.prototype.showAll=function()
{
	if(this.showCount==this.tbl.rows.length)return;
	this.defaultShowCount=this.showCount;
	this.showCount=this.tbl.rows.length;
	this.reinitPars();
	this.toFirstPage();
	return ;
	var rows=this.tbl.rows
	var lines=rows.length;
	if(lines){
		var line;
		for(var i=0;i<lines;i++){
			line=rows[i];
			line.className='trs';
			
		}
	}
}

PaginatedCtrl.prototype.paginate=function()
{
	this.setShowCount(this.defaultShowCount);
	this.toPage(1);
}

PaginatedCtrl.prototype.mylinkColor=function()
{
	var links=document.getElementsByTagName("a");
	var link;
	
	for(var i=0;i<links.length;i++)
	{
		link=links[i];
		link.className="navi_2nd";
		alert(link.className);
	}
}